import { DownloadOutlined, FileAddOutlined, FileExcelOutlined } from '@ant-design/icons';
import { Space } from 'antd';
import { AttachmentButton, Upload, UploadProps } from '../components';
import { ITableAttachmentProps } from '../interface';

const editOrViewDataMap = {
  edit: {
    text: '编辑',
    param: 'Edit',
    fileTypeList: ['doc', 'docx', 'xls', 'xlsx']
  },
  view: {
    text: '查看',
    param: 'View',
    fileTypeList: ['doc', 'docx', 'xls', 'xlsx', 'pdf']
  }
};
type ToolbarAction = 'delete' | 'download' | 'zipDownload';
export interface AttachmentToolbarProps extends UploadProps {
  permission: ITableAttachmentProps['permission'];
  uploadRef: any;
  uploading?: boolean;
  isReady?: boolean;
  onToolbarClick: (action: ToolbarAction) => void;
}
export function Toolbar(props: AttachmentToolbarProps) {
  const { permission, uploadRef, uploading, isReady, onToolbarClick, ...rest } = props;
  return (
    <Space size={[15, 10]} wrap>
      {permission?.add === 2 ? null : (
        <Upload {...rest} ref={uploadRef}>
          <AttachmentButton
            permissionStatus={permission?.add}
            disabled={!isReady || uploading}
            icon={<FileAddOutlined />}
          >
            <span>新增</span>
            {/* <CaretDownOutlined /> */}
          </AttachmentButton>
        </Upload>
      )}
      <AttachmentButton
        permissionStatus={permission?.delete}
        icon={<FileExcelOutlined />}
        onClick={() => onToolbarClick('delete')}
      >
        删除
      </AttachmentButton>
      {/* <AttachmentButton
        permissionStatus={permission?.edit}
        icon={<FormOutlined />}
        onClick={() => onToolbarClick('edit')}
      >
        编辑
      </AttachmentButton>
      <AttachmentButton
        permissionStatus={permission?.view}
        icon={<FileSearchOutlined />}
        onClick={() => onToolbarClick('view')}
      >
        查看
      </AttachmentButton> */}
      <AttachmentButton
        permissionStatus={permission?.download}
        icon={<DownloadOutlined />}
        onClick={() => onToolbarClick('download')}
      >
        下载
      </AttachmentButton>
      <AttachmentButton
        permissionStatus={permission?.zipDownload}
        icon={<DownloadOutlined />}
        onClick={() => onToolbarClick('zipDownload')}
      >
        打包下载
      </AttachmentButton>
      {/* {tableAttachInfo?.billAttachTypeList?.length ? (
        <AttachmentButton
          permissionStatus={permission?.editCategory}
          icon={<FileSearchOutlined />}
          onClick={() => onToolbarClick('editCategory')}
        >
          编辑分类
        </AttachmentButton>
      ) : null} */}
    </Space>
  );
}
